import Vue from "vue";
import Vuex from "vuex";
import {reqSearchList} from "@/api";

Vue.use(Vuex);

// 数据
let state = {
    searchList:[] //三级联动列表
};

// 写好逻辑后，提交给mutations处理修改数据
let actions = {
     reqSearchList(context,params){
         reqSearchList(params).then(value =>{
              context.commit('REQSEARCHLIST',value.data.data)
          })
    },
};

// 只有mutations能够修改数据
let mutations = {
    REQSEARCHLIST(state,value){
        state.searchList = value;
    },

};

// 优化数据结构，过滤数据
let getters = {
    goodsList(state){
        return state.searchList.goodsList
    },
    attrsList(state){
        return state.searchList.attrsList
    },
    trademarkList(state){
        return state.searchList.trademarkList
    },


};


export default {
    namespaced:true,
    state,
    mutations,
    actions,
    getters
}
